package com.systemic.config;

import com.systemic.websocket.ChatHandshakeInterceptor;
import com.systemic.websocket.ChatWebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * @ClassName: WebsocketConfig
 * @Description: websocket配置类  把处理器和拦截器注册到spring websocket中
 * @Author:
 * @CreateTime: 2024-01-01 14:48
 * @Version:
 **/

@Configuration
@EnableWebSocket
public class WebsocketConfig implements WebSocketConfigurer {

    @Resource
    private ChatWebSocketHandler webSocketHandler;

    @Resource
    private ChatHandshakeInterceptor chatHandshakeInterceptor;


    /**
     * 注册具体服务，客户端实际访问的服务路径
     * @param registry
     */
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //添加处理器, 定义处理器的处理路径，比如 "/chat"
        registry.addHandler(webSocketHandler, "/chat").addInterceptors(chatHandshakeInterceptor);
    }
}
